<?
require_once("conn.php");
$flag = Array("","A","B","C","D","E","F","G","H","I","J","K","L","M");

for($i=1;$i<=13;$i++){
	$sql = "SELECT * FROM pch_product WHERE category_id='".$i."';";
	//echo $sql."<br>";
	$query = mysql_query($sql) or die(mysql_error());
	$x=1;
	while($row = mysql_fetch_array($query)){
		$tmp = $x;
		if(strlen($tmp) == 1){
			$tmp = $flag[$i]."000".$tmp;
		}else if(strlen($tmp) == 2){
			$tmp = $flag[$i]."00".$tmp;
		}else if(strlen($tmp) == 3){
			$tmp = $flag[$i]."0".$tmp;
		}else if(strlen($tmp) == 4){
			$tmp = $flag[$i].$tmp;
		}
		$ssql = "UPDATE pch_product SET barcode='".$tmp."' WHERE id='".$row["id"]."';";
		//echo $ssql."<br>";
		mysql_query($ssql) or die(mysql_error());
		$x++;
	}
}
?>